﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

namespace CSharpTest
{
    class Program
    {

        public const string DayTimeFormat = "HH:mm:ss";
        public static readonly Regex DayTimeFormatRegex = new Regex(@"\d{2}:\d{2}:\d{2}");

        public const string TimeFormat = "yyyy-MM-dd HH:mm:ss";
        public static readonly Regex TimeFormatRegex = new Regex(@"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}");

        static void Main(string[] args)
        {

            //string timeStr = "16:02:23";

            //DateTime dateTime = DateTime.MinValue;

            //if (DayTimeFormatRegex.IsMatch(timeStr))
            //{
            //    dateTime = DateTime.ParseExact(timeStr, DayTimeFormat, null);
            //}
            //else if (TimeFormatRegex.IsMatch(timeStr))
            //{
            //    dateTime = DateTime.ParseExact(timeStr, TimeFormat, null);
            //}

            //Console.WriteLine(dateTime);
            //Console.WriteLine("123qwe七八九".Length);
            //string str = "123qwe七八九";
            //for (int i = 0; i < str.Length; i++)
            //{
            //    Console.WriteLine($"{str[i]} : {isChinese(str[i])}");
            //}


            //List<A> list = new List<A>()
            //{
            //    new A(1),
            //    new A(2),
            //    new A(3),
            //    new A(4),
            //    new A(5),
            //    new A(6),
            //    new A(7),
            //    new A(8),
            //};

            //Comparison<A> comparison = (a1, a2) =>
            //{
            //    if ((AEnum)a1.aEnumInt == (AEnum)a1.aEnumInt)
            //    {
            //        return 0;
            //    }
            //    if ((AEnum)a1.aEnumInt == AEnum.A)
            //    {
            //        return -1;
            //    }
            //    if ((AEnum)a1.aEnumInt == AEnum.A)
            //    {
            //        return 1;
            //    }
            //    return a1.aEnumInt.CompareTo(a1.aEnumInt);
            //};

            //list.Sort(comparison);


            //string[] strSplit1 = Regex.Split(str, "[0-9]", RegexOptions.IgnoreCase);


            //for (int i = 0; i < strSplit1.Length; i++)
            //{
            //    Console.WriteLine(strSplit1[i]);
            //}

            //例：（可以："123str123_456","str_123abc"," str ","str@"）(不行："123str123_/456","/str_123abc"," str /","/str@/")

            //string txt = "\"12_Abc\"";

            //string str = "abc";

            //string pattern = $@"({"\""})+[^\\\/]*({str})+[^\\\/]*({"\""})";

            //Console.WriteLine(txt);
            //Console.WriteLine(str);

            //Console.WriteLine(Regex.IsMatch(txt, pattern));


            //UIMemberOpBtnType type = UIMemberOpBtnType.None | UIMemberOpBtnType.Chat;

            //Console.WriteLine(type.HasFlag(UIMemberOpBtnType.None));

            //string a = "{123}";
            //string b =null;

            //Console.WriteLine(string.Format($"{a}", b));

            //List<int> list = null;

            //var cnt = list?.Count;
            //for (int i = 0; i < cnt; i++)
            //{
            //    Console.WriteLine($"{2f:+0.##;-0.##;0.##}%");
            //}

            //A a = new A();
            //a.b = new B();

            //if (a?.b == null)
            //{
            //    Console.WriteLine("a?.b == null");
            //}
            //else
            //{
            //    Console.WriteLine("else");
            //}

            //Console.WriteLine(a?.aEnumInt.ToString());
            //Console.WriteLine($"{1234.56f:+N.##;-N.##;N.##}%");
            //Console.WriteLine(1234.56f.ToString("N2"));
            //Console.ReadKey();

            //bool a = true;
            //bool b = false;
            //bool c = true;

            //for (int x = 0; x < 2; x++)
            //{
            //    a = x == 1;
            //    for (int y = 0; y < 2; y++)
            //    {
            //        b = x == 1;
            //        for (int z = 0; z < 2; z++)
            //        {
            //            c = x == 1;

            //            bool d = a ? (b && c) : b;
            //            Console.WriteLine(d);


            //            d = b && (!a || c);
            //            Console.WriteLine(d);

            //            bool f = a ? c : true;

            //            f = !a || c;

            //            d = b && (!a || c);
            //            Console.WriteLine(d);

            //            Console.WriteLine("--------------------------");

            //            Console.ReadKey();

            //        }
            //    }
            //}
            //Dictionary<int, int> dic = new Dictionary<int, int>();


            //dic.Add(1, 5);
            //dic.Add(0, 0);
            //dic.Add(2, 3);
            //dic.Add(3, 1);

            //var value = dic[dic.Keys.ToArray()[dic.Count - 1]];

            //Console.WriteLine(value);

            //Console.ReadKey();

            //ChineseSort();

            //return;

            string[] strs = File.ReadAllLines(@"E:\Desktop\新建文本文档.txt");
            int len = strs.Length;
            string[] newStrs = new string[len * 2];
            for (int i = 0; i < len; i++)
            {
                string str = strs[i];
                int overIndex = str.LastIndexOf('。');
                int timeIndex = str.LastIndexOf('D');
                newStrs[i] = str.Substring(0, overIndex + 1);
                newStrs[len + i] = str.Substring(overIndex + 1, timeIndex - overIndex - 1);
            }

            File.WriteAllLines(@"E:\Desktop\新建文本文档1.txt", newStrs, encoding: Encoding.UTF8);
        }

        private static void ChineseSort()
        {
            List<string> strList = new List<string>() { "b", "a", "c", "g", "f", "h", "z", "m" };

            strList.Sort();

            string log = string.Empty;
            for (int i = 0; i < strList.Count; i++)
            {
                log += $"[{strList[i]}:{(int)(strList[i].ToCharArray()[0])}] ";
            }

            Console.WriteLine(log);
            Console.ReadKey();
        }


        /// <summary>
        /// 传入能转换成数字或者小数的任意类型，返回中文大写数字(一、二、三)
        /// </summary>
        public static string ConvertToChineseUpper(object value)
        {
            try
            {
                string hash = double.Parse(value.ToString()).ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
                string results = Regex.Replace(hash, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[.]|$))))", "${b}${z}");
                hash = Regex.Replace(results, ".", delegate (Match m)
                {
                    return "负点空〇一二三四五六七八九空空空空空空空分角十百千万亿兆京垓秭穰"[m.Value[0] - '-'].ToString();
                });
                if (hash.Substring(hash.Length - 1, 1) == "点")
                {
                    hash = hash.Replace("点", "");
                    return hash;
                }
                else
                {
                    hash = hash.Replace("角", "").Replace("分", "");
                    return hash;
                }
            }
            catch (Exception)
            {
                return "〇";
            }
        }

        private static void Do(params string[] args)
        {
            args = new string[args.Length];
            for (int i = 0; i < args.Length; i++)
            {
                args[i] = "";
            }
        }

        private static List<int> GetList()
        {
            return new List<int>() { 0, 1, 2 };
        }

        private static string TirmSpace(string value)
        {
            return value.Replace(" ", "");
        }

        public static bool isChinese(char c)
        {
            return c >= 0x4E00 && c <= 0x9FA5;
        }

        public class A
        {

            public B b;
            public int aEnumInt;

            public A(int aEnumInt)
            {
                this.aEnumInt = aEnumInt;
            }
            public A()
            {
            }
        }

        public class B : A
        {
            public int a;
        }

        public class C : A
        {
            public int a;
        }

        public static void Do()
        {
            List<B> bList = new List<B>();

            Sort(bList);
        }

        public static void Sort(List<A> list)
        {

        }

        enum AEnum
        {

            A = 0,
            B = 1,
            C = 2,
            D = 3

        }


        [Flags]
        /// <summary> 成员操作按钮类型 </summary>
        enum UIMemberOpBtnType
        {

            None = 1 << 0,

            /// <summary> 个人信息 </summary>
            Info = 1 << 1,

            /// <summary> 位置 </summary>
            Pos = 1 << 2,

            /// <summary> 私聊 </summary>
            Chat = 1 << 3,

            /// <summary> 写邮件 </summary>
            Mail = 1 << 4,

            /// <summary> 增援 </summary>
            Reinforce = 1 << 5,

            /// <summary> 资源援助 </summary>
            Resources = 1 << 6,

            /// <summary> 升级/降级 </summary>
            ChangeLevel = 1 << 7,

            /// <summary> 任命 </summary>
            Appoint = 1 << 8,

            /// <summary> 移除盟友 </summary>
            Remove = 1 << 9,

            /// <summary> 加为好友 </summary>
            BeFriend = 1 << 10

        }


    }

}
